package com.lb.shopguide.im.session.extension;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lb.shopguide.entity.goods.GoodsInChatBean;
import com.lb.shopguide.entity.goods.GoodsInListBean;

/**
 * Created by kang on 2017/6/6.
 */

public class GoodsAttachment extends CustomAttachment {
    private GoodsInChatBean goodsItem;

    public GoodsAttachment(JSONObject data) {
        super(CustomAttachmentType.Goods);
        goodsItem = JSON.parseObject(data.toString(), GoodsInChatBean.class);
    }

    public GoodsAttachment(GoodsInChatBean item) {
        super(CustomAttachmentType.Goods);
        goodsItem = item;
    }

    @Override
    public String toJson(boolean send) {
        JSONObject data = (JSONObject) JSON.toJSON(goodsItem);
        return CustomAttachParser.packData(CustomAttachmentType.Goods, data);
    }

    @Override
    protected void parseData(JSONObject data) {
        goodsItem = JSON.parseObject(data.toString(), GoodsInChatBean.class);
    }

    @Override
    protected JSONObject packData() {
        return (JSONObject) JSON.toJSON(goodsItem);
    }

    public GoodsInChatBean getGoodsInOrder() {
        return goodsItem;
    }
}
